#来源
看到别人网站上的百度收录查询,感觉挺好看的。
抄一个。
#代码实现
//展示百度收录
function baidu_check($url){
global $wpdb;
$post_id = ( null === $post_id ) ? get_the_ID() : $post_id;
$baidu_record = get_post_meta($post_id,'baidu_record',true);
if( $baidu_record != 1){
$url='https://www.baidu.com/s?wd='.$url;
$curl=curl_init();
curl_setopt($curl,CURLOPT_URL,$url);
curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
$rs=curl_exec($curl);
curl_close($curl);
if(!strpos($rs,'沒有找到')){
if( $baidu_record == 0){
update_post_meta($post_id, 'baidu_record', 1);
} else {
add_post_meta($post_id, 'baidu_record', 1, true);
}
return 1;
} else {
if( $baidu_record == false){
add_post_meta($post_id, 'baidu_record', 0, true);
}
return 0;
}
} else {
return 1;
}
}
function baidu_record() {
if(baidu_check(get_permalink()) == 0) {
echo '<a target="_blank" title="点击查看" rel="external nofollow" href="https://www.baidu.com/s?wd='.get_the_title().'">百度已收录</a>';
} else {
echo '<a style="color:red;" rel="external nofollow" title="点击提交,谢谢您!" target="_blank" href="https://zhanzhang.baidu.com/sitesubmit/index?sitename='.get_permalink().'">百度未收录</a>';
}
}
然后在想加入的位置加上
<?php baidu_record(); ?>
例如:

#效果
效果如下:


后续问题
后续发现没有特色图片的是正常的,如果一个页面存在特色图片,那么就不会显示,经过查找代码,发现再inc/theme_plus.php中还有一份代码
我这边一共搜到了三份,都进行修改
修改后的如下,我的再307行。
$t .= '<p class="entry-census"><span><a href="'. esc_url(get_author_posts_url(get_the_author_meta('ID'),get_the_author_meta( 'user_nicename' ))) .'"><img src="'. get_avatar_url( get_the_author_meta('ID'), 64 )/*$ava*/ .'"></a></span><span><a href="'. esc_url(get_author_posts_url(get_the_author_meta('ID'),get_the_author_meta( 'user_nicename' ))) .'">'. get_the_author() .'</a></span><span class="bull">·</span>'. poi_time_since(get_post_time('U', true),false,true) .'<span class="bull">·</span>'. get_post_views(get_the_ID()) .' '._n("View","Views",get_post_views(get_the_ID()),"sakura")/*次阅读*/.$edit_this_post_link.baidu_record2().' </p>';
其中baidu_record2的代码需要放到functions.php中
function baidu_record2() {
if(baidu_check(get_permalink()) == 0) {
return '<a target="_blank" title="点击查看" rel="external nofollow" href="https://www.baidu.com/s?wd='.get_the_title().'">百度已收录</a>';
} else {
return '<a style="color:red;" rel="external nofollow" title="点击提交,谢谢您!" target="_blank" href="https://zhanzhang.baidu.com/sitesubmit/index?sitename='.get_permalink().'">百度未收录</a>';
}
return "";
}
与前面的代码放到一起。
效果如下:

Comments | 1 条评论
但是不知道为什么,有的网站有,有的网站没有。